package arrayprocessing;
/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 *
 * @author danh.ngothanh
 */
public class Main {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        // TODO code application logic here
        String color_code = "F7213E5F";
        long color_value_32bits = Long.parseLong(color_code, 16);
        int color_value_16bits = Color_32bits_to_Color_16bits(color_value_32bits);
        System.out.println(Integer.toHexString(color_value_16bits));

    }

    private static int Color_32bits_to_Color_16bits(long color_value_32bits){
        int alpha_value = (int)(color_value_32bits >> 28);
        int red_value = (int)(color_value_32bits >> 20) & 15;
        int green_value = (int)(color_value_32bits >> 12) & 15;
        int blue_value = (int)(color_value_32bits >> 4) & 15;
        int return_value = alpha_value;
        return_value = (return_value << 4) | red_value;
        return_value = (return_value << 4) | green_value;
        return_value = (return_value << 4) | blue_value;
        return return_value;
    }

    private static void print_1d_int_array(int[] array){
        System.out.println();
        int array_length = array.length;
        for(int i = 0; i < array_length; i ++){
            System.out.print(array[i]);
            if(i != (array_length - 1))
                System.out.print(", ");
        }
        System.out.println();
    }
    private static void print_2d_int_array(int[][] array){
        System.out.println();
        int array_row_num = array.length;
        int array_col_num = array[0].length;
        for(int i = 0; i < array_row_num; i ++){
            for(int j = 0; j < array_col_num; j ++){
                System.out.print(array[i][j]);
                if(j != (array_col_num - 1))
                    System.out.print(", ");
            }
            System.out.println();
        }
        System.out.println();
    }

    private static int[] array2d_to_array1d(int[][] array){
        int num_row = array.length;
        int num_col = array[0].length;
        int[] return_array = new int[num_row*num_col];
        for(int i = 0; i < num_row; i ++){
            for(int j = 0; j < num_col; j ++){
                return_array[(i*num_col+j)] = array[i][j];
            }
        }
        return return_array;
    }

    private static int[][] array1d_to_array2d(int[] array, int num_row, int num_col){
        int[][] return_array = new int[num_row][num_col];
        for(int i = 0; i < num_row; i ++){
            for(int j = 0; j < num_col; j ++){
                return_array[i][j] = array[(i*num_col+j)];
            }
        }
        return return_array;
    }

    private static int[][] rotate_2d_in_array(int[][] array, boolean is_clockwise){
        int array_row_num = array.length;
        int array_col_num = array[0].length;
        int[][] tmp_array = new int[array_col_num][array_row_num];
        for(int i = 0; i < array_row_num; i ++){
            for(int j = 0; j < array_col_num; j ++){
                if(is_clockwise)
                    tmp_array[j][array_row_num - 1 - i] = array[i][j];
                else
                    tmp_array[array_col_num - 1 - j][i] = array[i][j];
            }
        }
        return tmp_array;
    }
}
